﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using FF.Method;
using FF.Entity;

namespace FF
{
    public partial class FormQueryGood : Form
    {
        public FormQueryGood()
        {
            InitializeComponent();
        }
        private string userId;
        public FormQueryGood(string userid)
        {
            InitializeComponent();
            this.userId = userid;
        }

        private void FormQueryGood_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBoxKeyword.Text == "")
            {
                MessageBox.Show("请输入查找条件！", "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxKeyword.Focus();
                return;
            }
            DataSet ds = GoodMethod.getGoodByKeyword(textBoxKeyword.Text.Trim());
            if (ds == null || ds.Tables.Count < 1 || ds.Tables[0].Rows.Count < 1)
            {
                MessageBox.Show("没有相关记录！", "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxKeyword.Focus();
                dataGridView1.DataSource = null;
                return;
            }
            dataGridView1.DataSource = ds.Tables[0];
            return;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            DataSet ds = GoodMethod.getGoodByKeyword("");
            if (ds == null || ds.Tables.Count < 1 || ds.Tables[0].Rows.Count < 1)
            {
                MessageBox.Show("没有相关记录！", "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxKeyword.Focus();
                return;
            }
            dataGridView1.DataSource = ds.Tables[0];
            textBoxKeyword.Text = "";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string selectedGoodId = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            Good good = GoodMethod.getGoodById(selectedGoodId);

            if (good != null)
            {
                FormGood form = new FormGood(selectedGoodId, FormGood.ACTION_TYPE_MODIFY_DELETE);
                //form.user = selectedUser;
                form.Owner = this;
                form.ShowDialog();
                if (textBoxKeyword.Text.Trim() == "")
                {
                    button2_Click(sender, e);
                }
                else
                {
                    button1_Click(sender, e);
                }
            }
        }
    }
}
